//
//  NSDictionary+PropertyCode.m

//

#import "NSDictionary+PropertyCode.h"

@implementation NSDictionary (PropertyCode)

- (void)propertyCode
{
    [self printfPropertyCode:@"req"];
}

-(void)printfPropertyCode:(NSString*)key{
#if DEVELOPMENT
    // 属性跟字典的key一一对应
    NSMutableString *codes = [NSMutableString string];
    // 遍历字典中所有key取出来
    [self enumerateKeysAndObjectsUsingBlock:^(id  _Nonnull key, id  _Nonnull obj, BOOL * _Nonnull stop) {
        // key:属性名
        NSString *code;
        if ([obj isKindOfClass:[NSString class]]) {
            code = [NSString stringWithFormat:@"@property (nonatomic ,copy) NSString *%@;//",key];
        }else if ([obj isKindOfClass:NSClassFromString(@"__NSCFBoolean")]){
            code = [NSString stringWithFormat:@"@property (nonatomic ,assign) BOOL %@;//",key];
        }else if ([obj isKindOfClass:[NSNumber class]]){
            code = [NSString stringWithFormat:@"@property (nonatomic ,assign) long %@;//",key];
        }else if ([obj isKindOfClass:[NSArray class]]){
            code = [NSString stringWithFormat:@"@property (nonatomic ,strong) NSArray *%@;//",key];
            NSArray *array = (NSArray*)obj;
            if (array.count>0) {
                if ([array[0] isKindOfClass:[NSDictionary class]]) {
                    [array[0] printfPropertyCode:key];
                }
            }
        }else if ([obj isKindOfClass:[NSDictionary class]]){
            code = [NSString stringWithFormat:@"@property (nonatomic ,strong) NSDictionary *%@;//",key];
            [(NSDictionary*)obj printfPropertyCode:key];
        }
        
        
        
        [codes appendFormat:@"\n%@\n",code];
        
    }];
    
    NSLog(@"key--%@\n%@",key,codes);
#endif
}

@end
